package kt.com.bilin.coin.ui.activity

import android.content.Context
import android.content.Intent
import android.widget.MediaController
import com.alibaba.android.arouter.facade.annotation.Route
import com.bilin.coin.R
import com.yanzhenjie.sofia.Utils
import kotlinx.android.synthetic.main.activity_simple_video_view_player.*
import kt.com.bilin.coin.common.PATH_SIMPLE_VIDEO
import kt.com.bilin.coin.helper.InjectBundle

@Route(path = PATH_SIMPLE_VIDEO)
class SimpleVideoViewPlayerActivity : BaseActivity(R.layout.activity_simple_video_view_player) {
    companion object {
        const val VIDEO_URL = "mVideoUrl"
    }

    private val mVideoUrl: String by InjectBundle()
    private var isPalyer = false
    override fun initView() {
        Utils.invasionStatusBar(this)
        ivBack.setOnClickListener { finish() }
    }

    private fun playVideo() {
        vvVideoView.setVideoPath(mVideoUrl)
        val mc = MediaController(this)
        mc.setAnchorView(vvVideoView)
        vvVideoView.setMediaController(mc)
        vvVideoView.start()
        vvVideoView.setOnPreparedListener { mp ->
            mp.start()
            mp.isLooping = true
        }
    }

    override fun onPause() {
        super.onPause()
        vvVideoView.pause()
    }

    override fun onResume() {
        super.onResume()
        if (isPalyer) {
            vvVideoView.resume()
        } else {
            playVideo()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        vvVideoView.stopPlayback()
    }
}